﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CrazyBeavers.Geodesy.Tests
{
    /// <summary>
    ///This is a test class for DistanceCalculatorTest and is intended
    ///to contain all DistanceCalculatorTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DistanceCalculatorTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Spherical
        ///</summary>
        [TestMethod()]
        public void SphericalTest()
        {
            GeodeticCoordinate coordinate1 = new GeodeticCoordinate() { Latitude = 63.83451, Longitude = 20.24655 };
            GeodeticCoordinate coordinate2 = new GeodeticCoordinate() { Latitude = 63.85763, Longitude = 20.33569 };
            double expected = 5.069d;
            double actual = DistanceCalculator.Spherical(coordinate1, coordinate2);
            Assert.AreEqual(Math.Round(expected, 3), Math.Round(actual, 3));
        }

        /// <summary>
        ///A test for Haversine
        ///</summary>
        [TestMethod()]
        public void HaversineTest()
        {
            GeodeticCoordinate coordinate1 = new GeodeticCoordinate() { Latitude = 63.83451, Longitude = 20.24655 };
            GeodeticCoordinate coordinate2 = new GeodeticCoordinate() { Latitude = 63.85763, Longitude = 20.33569 };
            double expected = 5.069d;
            double actual = DistanceCalculator.Haversine(coordinate1, coordinate2);
            Assert.AreEqual(Math.Round(expected, 3), Math.Round(actual, 3));
        }

        /// <summary>
        ///A test for CoordFromDistance
        ///</summary>
        [TestMethod()]
        public void CoordFromDistanceTest()
        {
            GeodeticCoordinate start = new GeodeticCoordinate() { Latitude = 63.83451, Longitude = 20.24655 };
            double bearing = 140d;
            double distance = 1.3d;
            GeodeticCoordinate expected = new GeodeticCoordinate() { Latitude = 63.8256, Longitude = 20.2636 };
            GeodeticCoordinate actual;
            actual = DistanceCalculator.CoordFromDistance(start, bearing, distance);
            Assert.IsTrue(expected.Equals(actual));
        }
    }
}
